﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CarExam.DBUtility;

namespace CarExam.DAL
{
    public class UserDAL
    {
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <param name="dt"></param>
        /// <returns>0:成功 1:失败</returns>
        public int UserLogin(string account, string password, out DataTable dt)
        {
            dt = null;
            SqlParameter[] param = {
                                           new SqlParameter("@account",account),
                                           new SqlParameter("@pwd",password),
                                           new SqlParameter("@returnValue",SqlDbType.Int)
                                       };
            param[param.Length - 1].Direction = ParameterDirection.ReturnValue;
            DataSet ds = DBUtility.DbHelperSQL.RunProcedure("Spm_UserLogin", param, "dt");
            if (ds != null && ds.Tables.Count > 0)
                dt = ds.Tables[0];
            return int.Parse(param[param.Length - 1].Value.ToString());
        }

        /// <summary>
        /// 退出登录时更新锁定登录状态值
        /// </summary>
        public bool UpdateIsLocked(int uid)
        {
            string sql = "update UserInfo set islocked=0 where UID=@uid";
            SqlParameter[] param = {
                                       new SqlParameter("@uid",uid)
                                   };
            return DBUtility.DbHelperSQL.ExecuteSql(sql, param) > 0 ? true : false;
        }
    }
}
